package com.heima.fangfa;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Method02 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        //获取class对象
        Class clss = Class.forName("com.heima.fangfa.Student");
        //返回指定public对象
        Method learn = clss.getMethod("learn", String.class);
        //运行learn方法
        //创建一个student对象，当做方法调用者
        Student s = (Student) clss.newInstance();
        //运行方法
        Object invoke = learn.invoke(s, "22");
        System.out.println(invoke);


    }
}
